<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const o = (function(){
      const obj = {
        a:1,
        b:2
      }
      // 预防2
      // Object.setPrototypeOf(obj,null)
      return {
        get:function(k){
          // 预防1
          // if(obj.hasOwnProperty(k)){
          //   return obj[k]
          // }
          // return undefined

          return obj[k]
        }
      }
    })()
    console.log(o.prototype)
    // 如何在不改变上面代码的情况下
    // 修改obj对象
    // console.log(o.get('a'))
    // console.log(o.get('b'))
    // console.log(o.get('c'))

    // this指向不对
    // console.log(o.get('valueOf')())

    Object.defineProperty(Object.prototype,'abc',{
      get(){
        return this
      }
    })
    console.log(Object.prototype)
    const obj2 = o.get('abc')
    console.log(obj2)
    obj2.c = 2
    console.log(obj2)
  </script>
</body>
</html>